package com.cci.kangdao.controller;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.UploadPicturesService;
import com.cci.kangdao.utilTool.ParameterTool;

@Controller
public class UploadPictures {
	/**
	 * 照片上传
	 * 
	 */
	private Logger log = Logger.getLogger(this.getClass().getName());
	
	@Autowired
	private UploadPicturesService uploadPicturesService;

	@RequestMapping("/UploadPictures.aspx")
	public ModelAndView UploadPictures(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return uploadPicturesService.upload(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	@RequestMapping("/getPicturesList.aspx")
	public ModelAndView getPicturesList(HttpServletRequest request,HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return uploadPicturesService.getPicturesList(map);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.error(e.getMessage(),e);
			ParameterTool.writeErrorResponse(response);
		}
		return null;
	}

	@RequestMapping("/getRemedyPictureList.aspx")
	public void getRemedyPictureList(HttpServletRequest request,HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			uploadPicturesService.getRemedyPictureList(map);
		} catch (Exception e) {
			log.error(e.getMessage(),e);
			ParameterTool.writeErrorResponse(response);
		}
	}

	@RequestMapping(value = "/getManagementPictureList.aspx")
	public void getManagementPictureList(HttpServletRequest request,HttpServletResponse response) {
		try {
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			uploadPicturesService.getManagementPictureList(map);
		} catch (UnsupportedEncodingException e) {
			log.error(e.getMessage(),e);
			ParameterTool.writeErrorResponse(response);
		}
	}

	@RequestMapping("/newUploadPictures.aspx")
	public void newUploadPictures(HttpServletRequest request, HttpServletResponse response)  {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			uploadPicturesService.newUpload(map);
		}catch(Exception ex) {
			log.error(ex.getMessage(), ex);
			ParameterTool.writeErrorResponse(response);
		}
	}

	@RequestMapping("/ocrUploadPictures.aspx")
	public void ocrUploadPictures(HttpServletRequest request, HttpServletResponse response)  {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			uploadPicturesService.ocrUploadPictures(map);
		}catch(Exception ex) {
			log.error(ex.getMessage(), ex);
			ParameterTool.writeErrorResponse(response);
		}
	}

	@RequestMapping("/deletePicture.aspx")
	public void deletePicture(HttpServletRequest request, HttpServletResponse response)  {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			uploadPicturesService.deletePicture(map);
		}catch(Exception ex) {
			log.error(ex.getMessage(), ex);
			ParameterTool.writeErrorResponse(response);
		}
	}
}
